package com.ruoyi.check.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.check.domain.BmSpecification;
import com.ruoyi.check.service.IBmSpecificationService;
import com.ruoyi.common.core.utils.JwtUtils;
import com.ruoyi.outbound.domain.BmOutbound;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.check.domain.BmCheck;
import com.ruoyi.check.service.IBmCheckService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 库存盘点Controller
 * 
 * @author ruoyi
 * @date 2023-08-07
 */
@RestController
@RequestMapping("/check")
public class BmCheckController extends BaseController
{
    @Autowired
    private IBmCheckService bmCheckService;

    @Autowired
    private IBmSpecificationService bmSpecificationService;

    /**
     * 查询库存盘点列表
     */
    @RequiresPermissions("inventory:check:list")
    @GetMapping("/list")
    public TableDataInfo list(BmCheck bmCheck)
    {
        startPage();
        List<BmCheck> list = bmCheckService.selectBmCheckList(bmCheck);
        return getDataTable(list);
    }

    /**
     * 导出库存盘点列表
     */
    @RequiresPermissions("inventory:check:export")
    @Log(title = "库存盘点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BmCheck bmCheck)
    {
        List<BmCheck> list = bmCheckService.selectBmCheckList(bmCheck);
        ExcelUtil<BmCheck> util = new ExcelUtil<BmCheck>(BmCheck.class);
        util.exportExcel(response, list, "库存盘点数据");
    }

    /**
     * 获取库存盘点详细信息
     */
    @RequiresPermissions("inventory:check:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bmCheckService.selectBmCheckById(id));
    }

    /**
     * 新增库存盘点
     */
    @RequiresPermissions("inventory:check:add")
    @Log(title = "库存盘点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmCheck bmCheck,@RequestHeader("Authorization") String authorization)
    {
        String claims = authorization.substring(7);
        String userId = JwtUtils.getUserId(claims);
        bmCheck.setCreateId(Long.valueOf(userId));
        bmCheckService.insertBmCheck(bmCheck);
        return AjaxResult.success();
    }

    /**
     * 修改库存盘点
     */
    @RequiresPermissions("inventory:check:edit")
    @Log(title = "库存盘点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmCheck bmCheck)
    {
        return toAjax(bmCheckService.updateBmCheck(bmCheck));
    }

    /**
     * 删除库存盘点
     */
    @RequiresPermissions("inventory:check:remove")
    @Log(title = "库存盘点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bmCheckService.deleteBmCheckByIds(ids));
    }

    @PutMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody BmCheck bmCheck) {
        return AjaxResult.success(bmCheckService.updateStatus(bmCheck));
    }

    @GetMapping("/getGoods")
    public TableDataInfo getGoods(BmSpecification bmSpecification) {
        startPage();
        List<BmSpecification> goods = bmSpecificationService.getGoods(bmSpecification);
        return getDataTable(goods);
    }

}
